<template>
  <div class="addContainer">
    <div
      style="
        height: 100%;
        padding-left: 150px;
        padding-right: 150px;
        overflow-y: auto;
        padding-bottom: 70px;
      "
    >
      <div style="padding: 20px">
        <el-card>
          <template #header>
            <span style="font-weight: bold; font-size: 16px">新增生产退料</span>
          </template>
          <div class="addBody">
            <div class="basicInfoContainer">
              <div class="milestone">
                <div class="milestone-content">基础信息</div>
              </div>
              <el-form
                style="margin-top: 40px"
                label-width="120"
                :model="returnForm"
              >
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="退料单编号" prop="returnListId">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.returnListId"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="退料单名称" prop="returnListName">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.returnListName"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="退料日期" prop="returnDate">
                      <el-date-picker
                        style="width: 300px"
                        type="date"
                        placeholder="请选择日期"
                        v-model="returnForm.returnDate"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="退料人" prop="returnPeople">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.returnPeople"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="工单名称" prop="workListName">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.workListName"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="工单编号" prop="workListId">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.workListId"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="任务名称" prop="taskName">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.taskName"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="任务编号" prop="taskId">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.taskId"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="工艺路线" prop="craftLine">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.craftLine"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="工序名称" prop="craftName">
                      <el-input
                        placeholder="请输入"
                        style="width: 300px"
                        v-model="returnForm.craftName"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="备注" prop="remark">
                  <el-input
                    v-model="returnForm.remark"
                    type="textarea"
                    style="width: 795px"
                  ></el-input>
                </el-form-item>
              </el-form>
            </div>
            <div class="bomContainer">
              <div class="bomInfoContainer">
                <div class="milestone">
                  <div class="milestone-content">物料清单</div>
                </div>
                <div class="buttonGroup" style="margin-top: 20px">
                  <el-button type="primary" style="width: 80px">添加</el-button>
                  <el-button type="primary" style="width: 80px" plain
                    >移除</el-button
                  >
                </div>
                <el-table border style="margin-top: 20px">
                  <el-table-column
                    type="selection"
                    align="center"
                    fixed="left"
                  ></el-table-column>
                  <el-table-column
                    type="index"
                    align="center"
                    label="序号"
                    width="60"
                    fixed="left"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="物料名称"
                    width="90"
                    fixed="left"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="物料编号"
                    width="90"
                    fixed="left"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="规格型号"
                    width="90"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="单位"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="领料批次号"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="本次退料数量"
                    width="110"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="退料原因"
                    width="90"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="生产日期"
                    width="90"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="到期日期"
                    width="90"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="仓库名称"
                    width="90"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="库区名称"
                    width="90"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="库位名称"
                    width="90"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="备注"
                    width="200"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    label="操作"
                    width="100"
                    fixed="right"
                  ></el-table-column>
                </el-table>
              </div>
            </div>
          </div>
        </el-card>
      </div>
    </div>
    <div class="footer" :class="{ 'footer-visible': isFooterVisible }">
      <div class="footerButton">
        <el-button type="primary" plain style="width: 80px" @click="close"
          >关闭</el-button
        >
        <el-button type="primary" style="width: 80px" @click="handleSubmit"
          >确定</el-button
        >
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ProductReturnAddParamsType } from "@/api/ProductReturn/params";
import { useRouter } from "vue-router";
import { onMounted, ref } from "vue";
import { ElMessage } from "element-plus";
import { postProductReturnAddApi } from "@/api/ProductReturn";

const $router = useRouter();

const returnForm = ref<ProductReturnAddParamsType>({
  returnListId: "",
  getMaterialNum: "",
  craftLine: "",
  workListId: "",
  workListName: "",
  returnPeople: "",
  returnListName: "",
  materialInfo: "",
  craftName: "",
  returnDate: "",
  taskName: "",
  taskId: "",
  remark: "",
});
const isFooterVisible = ref(false);

onMounted(() => {
  setTimeout(() => {
    isFooterVisible.value = true;
  }, 100);
});

const close = () => {
  $router.replace("/storage/entrance/return");
};

const handleSubmit = async () => {
  try {
    const res = await postProductReturnAddApi({
      returnListId: returnForm.value.returnListId,
      getMaterialNum: returnForm.value.getMaterialNum,
      craftLine: returnForm.value.craftLine,
      workListId: returnForm.value.workListId,
      workListName: returnForm.value.workListName,
      returnPeople: returnForm.value.returnPeople,
      returnListName: returnForm.value.returnListName,
      materialInfo: returnForm.value.materialInfo,
      craftName: returnForm.value.craftName,
      returnDate: returnForm.value.returnDate,
      taskName: returnForm.value.taskName,
      taskId: returnForm.value.taskId,
      remark: returnForm.value.remark,
    });
    ElMessage.success("新增成功");
    console.log(res);
    $router.replace("/storage/entrance/return");
  } catch (err) {
    console.log(err);
    ElMessage.error("新增失败");
  }
};
</script>

<style scoped lang="scss">
.addContainer {
  width: 100%;
  position: relative;
  height: 100%;
  transform: translate(0);
  .addBody {
    width: 100%;
    .basicInfoContainer,
    .bomInfoContainer {
      padding: 20px;
      .milestone {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 1.5px;
        background-color: #dfe2e7;
        .milestone-content {
          border: 1.5px solid #dfe2e7;
          padding: 10px;
          padding-left: 20px;
          padding-right: 20px;
          font-weight: bold;
          font-size: 15px;
          border-radius: 10px;
          z-index: 999;
          background-color: #fff;
          color: #1b9aee;
        }
      }
    }
    .bomInfoContainer {
      margin-top: 20px;
    }
  }
  .footer {
    z-index: 999;
    width: 100%;
    height: 70px;
    background-color: #fff;
    position: fixed;
    bottom: 0;
    left: 0;
    padding: 10px;
    display: flex;
    justify-content: center;
    box-shadow: 0 -8px 10px rgba(92, 92, 92, 0.1);
    transform: translateY(100%); // 初始状态在视口下方
    transition: transform 0.5s ease-out; // 添加过渡效果

    &.footer-visible {
      transform: translateY(0); // 显示时回到原位
    }
  }
}
</style>
